<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title></title>
    <c:import url="../../header.jsp"/>
</head>
<body>
<div class="content-warp">
    <div class="dgg-list-top-warp">
        <%-- <form id="searchFormAll" action="${basePath}/all_order/excel_export_all.do">--%>
        <div class="screen-search">

            <ul>
                <li>
                    <label>客户姓名：</label>
                    <input type="text" class="dggui-input dggui-input-normal" id="customerName" name="customerName" placeholder="输入客户姓名" maxlength="50">
                </li>
                <li>
                    <label>接单时间：</label>
                    <input type="text" readonly class="dggui-input dggui-time-range" id="receiveOrderDate" name="receiveOrderDate">
                    <i class="iconfont icon-rili"></i>
                </li>
                <li>
                    <label>流程人员：</label>
                    <select id="flowUserId" name="flowUserId" style="min-width: 80px; display: none;">
                    </select>
                </li>
                <li>
                    <label>所属生产事业部：</label>
                    <input type="hidden" id="productOrgIdHidden">
                    <select id="productOrgId" name="productOrgId">
                    </select>
                </li>
                <li>
                    <label>业务类型：</label>
                    <input type="hidden" name="typeCodeHidden" id="typeCodeHidden">
                    <div name="typeCode" id="typeCode"></div>
                </li>
                <li>
                    <label>产品：</label>
                    <select name="productCode" id="productCode" style="min-width: 80px; display: none;">
                    </select>
                </li>
                <li>
                    <label>渠道：</label>
                    <select name="channelCode" id="channelCode" class="dggui-select">
                        <option value=''>请选择</option>
                    </select>
                </li>
                <li>
                    <label>节点：</label>
                    <select name="nodeId" id="nodeId" class="dggui-select">
                        <option value=''>请选择</option>
                    </select>
                </li>
                <li>
                    <label>签单商务：</label>
                    <select id="signUserId" name="signUserId">
                    </select>
                </li>
                <li>
                    <label>签单部门：</label>
                    <div class="tree-select-warp">
                        <input type="text" class="dggui-input input-selct-tree" id="signOrg" name="signOrg" data-id=""
                               value="" style="width: 320px"/>
                    </div>
                </li>
                <li>
                    <label>订单状态：</label>
                    <select name="orderStatus" id="orderStatus" style="min-width: 80px; display: none;">
                    </select>
                </li>
                <li>
                    <label>超期状态：</label>
                    <select id="SQSTATUS" name="SQSTATUS" class="dggui-select">
                        <option value="">全部</option>
                        <option value="OUT_TIME_STATE1">未超期</option>
                        <option value="OUT_TIME_STATE2">分配超期</option>
                        <option value="OUT_TIME_STATE3">接收超期</option>
                        <option value="OUT_TIME_STATE4">节点超期</option>
                        <option value="OUT_TIME_STATE5">订单超期</option>
                    </select>
                </li>
                <li>
                    <label>签单时间：</label>
                    <input type="text" readonly class="dggui-input dggui-time-range" id="signTime" name="signTime">
                    <i class="iconfont icon-rili"></i>
                </li>
                <li>
                    <label>关键字：</label>
                    <input type="text" class="dggui-input dggui-input-large" id="searchKey" name="searchKey" placeholder="订单编号/生产单编号/客户号码" maxlength="50" style="width: 190px;">
                </li>
       <%--         <li>
                    <label>需求金额：</label>
                    <input type="number" class="dggui-input dggui-input-large" id="moneyMin" name="moneyMin"
                           placeholder="输入最小金额" min="0">~
                    <input type="number" class="dggui-input dggui-input-large" id="moneyMax" name="moneyMax"
                           placeholder="输入最大金额" min="0">
                </li>--%>
                <li>
                    <button class="dggui-btn searchBtn" onclick="tableReload();return false;">搜索</button>
                    <button class="dggui-btn dggui-btn-primary" onclick="cleanSearch();return false;">清空条件</button>
                    <d:hasUrlAuth authCode="RZSC_OPERATION_EXPORT">
                        <button class="dggui-btn dggui-btn-green"
                                onclick="excelExportAll('${basePath}/all_order/excel_export_all.do');return false;">导出
                        </button>
                    </d:hasUrlAuth>
                </li>

            </ul>

        </div>
        <%--</form>--%>

    </div>
    <div class="list-content">
        <div class="tool-bar">
            <div class="fl">
                <d:hasUrlAuth authCode="RZSC_OPERATION_CALL">
                    <a href="javascript:void(0)" class="dggui-btn" onclick="callPhoneByProduction($('#allOrderList'))">打电话</a>
                </d:hasUrlAuth>
                <d:hasUrlAuth authCode="RZSC_OPERATION_QZGZLR">
                    <a href="javascript:void(0)" class="dggui-btn" onclick="cardWorkEntry($('#allOrderList'),1)">权证工作录入</a>
                </d:hasUrlAuth>
                <d:hasUrlAuth authCode="RZSC_OPERATION_ZLGZLR">
                    <a href="javascript:void(0)" class="dggui-btn" onclick="cardWorkEntry($('#allOrderList'),2)">资料工作录入</a>
                </d:hasUrlAuth>
                <d:hasUrlAuth authCode="RZSC_OPERATION_PGGZLR">
                    <a href="javascript:void(0)" class="dggui-btn" onclick="cardWorkEntry($('#allOrderList'),3)">评估工作录入</a>
                </d:hasUrlAuth>
                <d:hasUrlAuth authCode="RZSC_OPERATION_ZDGZLR">
                    <a href="javascript:void(0)" class="dggui-btn" onclick="cardWorkEntry($('#allOrderList'),4)">驻点工作录入</a>
                </d:hasUrlAuth>
            </div>
            <div class="fr node-state">
                <ul>
                    <li class="over-finish">订单超期</li>
                    <li>节点超期</li>
                    <li class="over">接收超期</li>
                    <li class="not-finish">分配超期</li>
                </ul>
            </div>
        </div>
        <div class="table-warp">
            <table class="dggui-table" id="allOrderList">
            </table>
        </div>
    </div>
</div>

<c:import url="/WEB-INF/jsp/footer.jsp"/>
<script>
    var NORMAL = '${NORMAL}', TIME_OUT = '${TIME_OUT}';
    var tables;
    dggui.use(['table', 'select2', 'distpicker', 'dggdate','droptree'], function () {
        var table = dggui.table;
        var select2 = dggui.select2;
        var distpicker = dggui.distpicker;
        var dggdate = dggui.dggdate;
        var droptree = dggui.droptree;
        //初始化所属生产事业部
        syb("#productOrgId");
        select2.render({
            placeholder: "请选择",
            elem: $('#productOrgId'),
            allowClear: true,
            width: "160px"
        });
        //初始化订单状态
        commonTreeBookCode("#orderStatus", "RZSCORDER_STATUS", 1, 1, 1, true);
        select2.render({
            placeholder: "请选择",
            allowClear: true,
            elem: $('#orderStatus'),
            width: "160px"
        });
        select2.render({
            placeholder: "请选择",
            allowClear: true,
            elem: $('#productCode'),
            width: "160px"
        });
        select2.render({
            placeholder: "请选择",
            allowClear: true,
            elem: $('#channelCode'),
            width: "160px"
        });
        //初始化节点信息
        initAllNode("#nodeId");
        select2.render({
            placeholder: "请选择",
            allowClear: true,
            elem: $('#nodeId'),
            width: "160px"
        });
        //初始化业务类型及产品
        distpicker.render({

            url: "${basePath}/rzsc/common/tree_book_list.do?code=BUS_YT_DK&type=2&level=2", // 请求地址
            elem: '#typeCode', // 容器Id
            type: 2,
            placeholder: '选择业态',
            defaultParentCode: 'BUS_YT_DK',
            callback: function () {//如果不需要选产品就把callback整个方法注释掉
                var code = $("#typeCode .plug-in-code").val();
                initProductCode("#productCode", code);
                select2.render({
                    placeholder: "请选择",
                    allowClear: true,
                    elem: $('#productCode'),
                    width: "160px"
                });
                var produtId = $("#productCode").val();
                initChannel("#channelCode", produtId);
                select2.render({
                    placeholder: "请选择",
                    allowClear: true,
                    elem: $('#channelCode'),
                    width: "160px"
                });
            },
            callbackClear: function () {
                $("#productCode").find("option").remove();
                $("#productCode").append("<option value=''>请选择</option>");
                $("#channelCode").find("option").remove();
                $("#channelCode").append("<option value=''>请选择</option>");
            }
        });
        //渠道初始化
        $('#productCode').on('change', function (e) {
            var produtId = $("#productCode").val();
            initChannel("#channelCode", produtId);
            select2.render({
                placeholder: "请选择",
                allowClear: true,
                elem: $('#channelCode'),
                width: "160px"
            });
        });

        // 加载部门下拉框
        queryAllDep("#signOrg");
        //初始化流程人员
        initUser("RZSC_FLOW_USER", "role", "#flowUserId");
        select2.render({
            placeholder: "请选择",
            allowClear: true,
            elem: $('#flowUserId'),
            width: "160px"
        });
        //初始化签单商务
        initUser("bus_advisor", "role", "#signUserId");
        select2.render({
            placeholder: "请选择",
            allowClear: true,
            elem: $('#signUserId'),
            width: "160px"
        });
        //初始化签单时间
        dggdate.render({
            elem: '#signTime',
            type: 'date',
            range: '~'
        });
        dggdate.render({
            elem: '#receiveOrderDate',
            type: 'date',
            range: '~'
        });

        var opt = {
            "elem": "#allOrderList",
            "ajax": sysInfo.basePath + "/all_order/all_Order_json.do",
            "scrollX": "true",//是否开启横项滚动
            //"selectCheck": false, //多选,同时选中复选框
            "oneSelectCheck": true,//单选，同时选中复选框
            "fixedColumns": {//锁定列，只有开启scrollX时才生效
                "leftColumns": 4,//左侧锁定2列
                "rightColumns": 1//右侧锁定1列
            },
            "visible": true,
            "fnServerParams": function (aoData) {
                // var moneyMax = $("#moneyMax").val().trim();
                // var moneyMin = $("#moneyMin").val().trim();
                //搜索条件
                aoData = $.extend(aoData, {
                        customerPhone: $("#customerPhone").val(),
                        productOrgId: $("#productOrgId").val(),
                        statusAttr: $("#orderStatus").val(),
                        typeCode: $("#typeCode .plug-in-code").val(),
                        productId: $("#productCode").val(),
                        channelId: $("#channelCode").val(),
                        flowUserId: $("#flowUserId").val(),
                        signUserId: $("#signUserId").val(),
                        SQSTATUS: $("#SQSTATUS").val(),
                        signOrgOrBusId: $("#signOrg").attr("data-id"),
                        orderTime:$("#signTime").val(),
                        receiveOrderDate:$("#receiveOrderDate").val(),
                        searchKey: $("#searchKey").val(),
                        customerName: $("#customerName").val(),
                        // moneyMax: moneyMax,
                        // moneyMin: moneyMin,
                        nodeName: $("#nodeId").val()
                    }
                )
                return aoData;
            },
            "aoColumns": [{
                "sClass": "check-th",
                "title": "<input type='checkbox' class='checkall'>",
                "orderable": false,
                "render": function (data, type, full, meta) {
                    return '<input type="checkbox" class="checkchild" name="checkchild" value="' + data + '">';
                }
            },
                {
                    "title": "序号",
                    "orderable": false,
                    "render": function (data, type, full, meta) {
                        return meta.row + 1;
                    }
                },
                {
                    "title": "所属生产事业部",
                    "data": "productOrgName",
                    "orderable": false,
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title": "订单编号",
                    "orderable": false,
                    "data": "orderNo",
                    "render": function (data, type, full, meta) {
                        return ('<a href="javascript:;" class="dggui-link"  onclick="openBusinessDetail(\'' + full.orderNo + '\',\'' + full.orderId + '\')" /><span>' + data + '</span></a>');
                        /*return data;*/
                    }
                },
                {
                    "title": "生产订单编号",
                    "orderable": false,
                    "data": "scProductOrderNo",
                    "render": function (data, type, full, meta) {
                        var result = "";
                        result += '<a href="javascript:;"  class="dggui-link" onclick="openOrderInfoDetail(\'' + full.scProductOrderNo + '\',\'' + full.id + '\')" /><span>' + data + '</span></a>';
                        return result;
                    }
                },
                {
                    "title": "客户",
                    "orderable": false,
                    "data": "customerName",
                    "render": function (data, type, full, meta) {
                        return emptyStringConvert(full.customerName) + '<p>' + emptyStringConvert(full.customerPhone) + '</p>';
                    }
                },
                {
                    "title": "订单状态",
                    "orderable": false,
                    "data": "status",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title": "当前完成节点",
                    "orderable": false,
                    "data": "latestEndNodeName",
                    "render": function (data, type, full, meta) {
                        return emptyStringConvert(full.latestEndNodeName) + '<p>' + emptyStringConvert(full.latestEndNodeTime) + '</p>';
                    }
                },
                {
                    "title": "合同编号",
                    "orderable": false,
                    "data": "contractNo",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title": "接单时间",
                    "orderable": false,
                    "data": "receiveOrderDate",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                /*{
                    "title":"最新备注时间",
                    "orderable": false,
                    "data": "lastRemarkTime",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },*/
                {
                    "title": "业务类型",
                    "orderable": false,
                    "data": "businessProductName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title": "产品",
                    "orderable": false,
                    "data": "productName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title": "渠道",
                    "orderable": false,
                    "data": "channelName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title":"签单时间",
                    "orderable": false,
                    "data": "orderTime",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title": "签单商务/部门",
                    "orderable": false,
                    "data": "signUserName",
                    "render": function (data, type, full, meta) {
                        return emptyStringConvert(full.signUserName) + '<p>' + emptyStringConvert(full.signUserOrgName) + '</p>';
                    }
                },
                /*{
                    "title":"签单部门",
                    "orderable": false,
                    "data": "signUserOrgName",
                    "render": function (data, type, full, meta) {
                        //return data+'<p>'+full.signUserOrgName+'</p>';
                        return data;
                    }
                },*/
                {
                    "title": "流程人员",
                    "orderable": false,
                    "data": "flowUserName",
                    "render": function (data, type, full, meta) {
                        return data ? data + '<p>' + emptyStringConvert(full.flowUserOrgName) + '</p>' : '';
                    }
                },
                /*{
                    "title":"流程部门",
                    "orderable": false,
                    "data": "flowUserOrgName",
                    "render": function (data, type, full, meta) {
                        //return data ? data+'<p>'+full.flowUserOrgName+'</p>': '';
                        return data;
                    }
                },*/
                {
                    "title": "需求金额（元）",
                    "orderable": false,
                    "data": "loanAmount",
                    "render": function (data, type, full, meta) {
                        var htm = '<div class="order-render">' +
                        '<p><span >' + data ? data : '' + '</span></p>' +
                            '</div>'
                        return htm;
                    }
                },
                {
                    'title': '最新备注',
                    'data': "lastRemark",
                    "orderable": false,
                    "render": function (data, type, row, meta) {
                        return '<div class="line1" title="' + data + '"><p>' + strInterception(data, 10) + '</p></div>' + '<p>' + emptyStringConvert(row.lastRemarkTime) + '</p>';
                    }
                },
                {
                    "title": "售后单号",
                    "data": "afterSaleNo",
                    "orderable": false,
                    "render": function (data, type, full, meta) {
                        return checkIsEmpty(data)?"-":data;
                    }
                },
                {
                    "title": "售后状态",
                    "data": "afterSaleStatus",
                    "orderable": false,
                    "render": function (data, type, full, meta) {
                        return checkIsEmpty(data)?"-":data;
                    }
                },
                {
                    "title": "售后处理结果",
                    "data": "productHandleResultType",
                    "orderable": false,
                    "render": function (data, type, full, meta) {
                        return checkIsEmpty(data)?"-":data;
                    }
                },
                {
                    'title': '操作',
                    "orderable": false,
                    "render": function (data, type, row, meta) {
                        var htm = '<a href="javascript:void(0)" class="dggui-link" onclick="remarkOrder(\'' + row.id + '\',$(\'#allOrderList\'));">备注</a>';
                        return htm;
                    }
                }
            ],
            "columnDefs": [{
                targets: [3], //第1，2，3列
                createdCell: function (td, cellData, rowData, row, col) {
                    if (rowData.orderTimeStatus == '${TIME_OUT}'&& rowData.status != '已退单' && rowData.status != '已废单') {
                        $(td).parent().addClass("red");//订单超期
                        return;
                    } else if (rowData.nodeTimeStatus == '${TIME_OUT}' && rowData.status != '已退单' && rowData.status != '已废单') {//节点超期
                        $(td).parent().addClass("green");
                        return
                    } else if (rowData.receiveTimeStatus == '${TIME_OUT}' && (rowData.status == '下单待接收' || rowData.status == '移交待接收' || rowData.status == '转单待接收' || rowData.status == '退回待接收')) {//接收超期
                        $(td).parent().addClass("purple");
                        return;
                    } else if (rowData.distributionTimeOutStatus == '${TIME_OUT}' && rowData.status == '待分配') {//分配超期
                        $(td).parent().addClass("gray");//分配
                        return;
                    }
                }
            }]
        };
        tables = table.render(opt);
        // 处理dataTable 异常错误信息
        $.fn.dataTable.ext.errMode = 'none';//不抛出异常
        tables.on('error.dt', function (e, settings, techNote, message) {
            //dggui.dialog.errors("表格查询错误，请联系管理员", 2000);
            if (checkEmpty(settings.jqXHR.responseJSON.error)) {
                dggui.dialog.errors(settings.jqXHR.responseJSON.error, 2000);
            }
        });
    });

    //列表刷新
    function tableReload() {
   /*     var moneyMax = $("#moneyMax").val().trim();
        var moneyMin = $("#moneyMin").val().trim();
        if (!checkMoneySearch(moneyMin, moneyMax)) {
            return false;
        }*/
        tables.ajax.reload();
        //$("#allOrderList").dataTableExtend('reload');
    }

    /**
     * 导出
     * */
    function excelExportAll(url) {

        // var moneyMax = $("#moneyMax").val().trim();
        // var moneyMin = $("#moneyMin").val().trim();
        // if (!checkMoneySearch(moneyMin, moneyMax)) {
        //     return;
        // }
        var obj = new Object();
        obj.customerPhone = $("#customerPhone").val();
        obj.productOrgId = $("#productOrgId").val();
        obj.typeCode = $("#typeCode").find(".plug-in-code").val();
        obj.productId = $("#productCode").val();
        obj.signUserId = $("#signUserId").val();
        obj.channelId=$("#channelCode").val();
        obj.orderTime = $("#signTime").val();
        obj.receiveOrderDate = $("#receiveOrderDate").val();
        obj.searchKey = $("#searchKey").val();
        obj.flowUserId = $("#flowUserId").val();
        obj.SQSTATUS = $("#SQSTATUS").val();
        obj.statusAttr = $("#orderStatus").val();
        obj.signOrgOrBusId = $("#signOrg").attr("data-id");
        obj.customerName=$("#customerName").val();
        obj.nodeNameExport=$("#nodeId").val(); //节点编码,因nodename名称和jq冲突换个名称
        // obj.moneyMax = moneyMax;
        // obj.moneyMin = moneyMin;
        formSubmit(url, obj);
    }

</script>

</body>
</html>